/*

 */
package com.ohos.connent.modelcloud.biz.modular.pro.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.modelcloud.biz.modular.pro.entity.BizProfile;
import com.ohos.connent.modelcloud.biz.modular.pro.param.*;
import com.ohos.connent.modelcloud.biz.modular.pro.result.BizProfileUploadAuthResult;
import com.ohos.connent.modelcloud.biz.modular.pro.service.BizProfileService;
import com.ohos.connent.modelcloud.common.annotation.CommonLog;
import com.ohos.connent.modelcloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 品类文件管理控制器
 **/
@Api(tags = "Profile文件管理控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 1)
@RestController
@RequestMapping(value = "/api/v1/model/biz/profile")
@Validated
public class BizProfileController {

    @Resource
    private BizProfileService bizProfileService;


    /**
     * 获取Profile文件管理分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取Profile文件管理分页数据")
    @PostMapping("/page")
    public CommonResult<Page<BizProfile>> page(@RequestBody BizProfilePageParam bizProfilePageParam) {
        return CommonResult.data(bizProfileService.page(bizProfilePageParam));
    }

    /**
     * 获取Profile文件管理列表
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取Profile文件管理列表")
    @PostMapping("/list")
    public CommonResult<List<BizProfile>> list(BizProfileListParam bizProfileListParam) {
        return CommonResult.data(bizProfileService.list(bizProfileListParam));
    }

    /**
     * 返回文件上传授权URL和文件id
     *
     *
     **/
    @ApiOperationSupport(order = 2)
    @ApiOperation("获取华为云文件上传授权URL和文件id")
    @CommonLog("获取华为云文件上传授权URL和文件id")
    @PostMapping("/file/getHWYunUploadAuthUrlAndFileId")
    public CommonResult<BizProfileUploadAuthResult> getHWYunUploadAuthUrlAndFileId(@RequestBody @Valid BizProfileUploadParam bizProfileUploadParam) {
        return CommonResult.data(bizProfileService.getHWYunUploadAuthUrlAndFileId(bizProfileUploadParam));
    }

    /**
     * 新增Profile文件
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("新增Profile文件")
    @CommonLog("新增Profile文件")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizProfileAddParam bizProfileAddParam) {
        bizProfileService.add(bizProfileAddParam);
        return CommonResult.ok();
    }

    /**
     * 删除Profile文件：逻辑删除
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除Profile文件")
    @CommonLog("删除Profile文件")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid BizProfileIdsParam bizProfileIdsParam) {
        bizProfileService.delete(bizProfileIdsParam);
        return CommonResult.ok();
    }


    /**
     * 获取华为云文件下载授权URL
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取华为云文件下载授权URL")
    @CommonLog("获取华为云文件下载授权URL")
    @PostMapping("/file/getFileDownloadAuthUrlHUAWEI")
    public CommonResult<String> getFileDownloadAuthUrlHUAWEI(@RequestBody @Valid BizProfileFileIdParam bizProfileFileIdParam) {
       return CommonResult.data(bizProfileService.getFileDownloadAuthUrlHUAWEI(bizProfileFileIdParam));
    }

    /**
     * 上传Profile文件
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("上传Profile文件")
    @CommonLog("上传Profile文件")
    @PostMapping("/file/upload")
    public CommonResult<String> upload(@RequestPart("file") MultipartFile file,
                                       @RequestParam @NotEmpty(message = "文件id不能为空") String fileId) {
        bizProfileService.upload(file, fileId);
        return CommonResult.ok();
    }

}
